*** Keywords ***
Set Window Size Js
    [Arguments]    ${width}    ${height}
    ${js}=    Set variable    window.moveTo(0, 0);window.resizeTo(${width},${height});
    ${visible}=    Execute Javascript    ${js}

UW Search Loading
    [Documentation]    核保系统查询加载
    ${js}=    Set Variable    return document.getElementsByClassName("overlay")[0].style.display
    # ${display}=    Execute Javascript    ${js}
    FOR    ${var}    IN RANGE    0    99999
        ${display}=    Execute Javascript    ${js}
        EXIT FOR LOOP IF    'none'=='${display}'
    END
    ${js}=    Set Variable    return document.getElementsByClassName("overlay")[0].style.display
    # ${display}=    Execute Javascript    ${js}
    FOR    ${var}    IN RANGE    0
        ${display}=    Execute Javascript    ${js}
        EXIT FOR LOOP IF    'none'=='${display}'
    END

Get Format Error Label
    [Arguments]    ${CssSelector}
    [Documentation]    function GetFormatError(css) {
    ...    var texts = document.getElementsByClassName(css);
    ...    var length = texts.length;
    ...    var indexs = new Array();
    ...
    ...    for (i = 0; i < length; i++) {
    ...    var txt = texts[i].parentNode.previousElementSibling.innerText;
    ...    var pos = txt.indexOf("统一社会信用代码");
    ...    if (pos != -1) {
    ...    var index = texts[i].parentNode.previousElementSibling.children[1].value;
    ...    indexs.push(index);
    ...    continue;
    ...    }
    ...    pos = txt.indexOf("身份证");
    ...    if (pos != -1) {
    ...    var index = texts[i].parentNode.previousElementSibling.children[0].value;
    ...    indexs.push(index);
    ...    continue;
    ...    }
    ...    indexs.push(txt);
    ...    }
    ...    return indexs;
    ...    }
    ${js}=    set Variable    function GetFormatError(css){var texts=document.getElementsByClassName(css);var length=texts.length;var indexs=new Array();for(i=0;i<length;i++){var txt=texts[i].parentNode.previousElementSibling.innerText;pos=txt.indexOf("身份证");if(pos!=-1){var index=texts[i].parentNode.previousElementSibling.children[0].value;indexs.push(index);continue}var pos=txt.indexOf("统一社会信用代码");if(pos!=-1){var index=texts[i].parentNode.previousElementSibling.children[1].value;indexs.push(index);continue}}return indexs};
    ${texts}=    Execute JavaScript    ${js} return GetFormatError(${CssSelector});
    [Return]    ${texts}

Scroll Element In View
    [Arguments]    ${locator}
    # window.scrollY 与当前元素的高度大小比较
    ${height_top}=    Get Vertical Position    ${LQuanping}
    ${height}=    Get Vertical Position    ${locator}
    ${Horizontal}=    Get Horizontal Position    ${locator}
    #滚动
    Execute Javascript    window.scrollBy(0,-120000);
    ${height1}=    Evaluate    ${height}-320-200
    run keyword if    ${Horizontal} < 0    Execute Javascript    window.scrollBy(-${Horizontal},${height1});
    ...    ELSE    Execute Javascript    window.scrollBy(0,${height1});

Element Should Be In View
    [Arguments]    ${element}
    ${js}=    Set Variable    function(element){var bounding=element.getBoundingClientRect();return(bounding.top>=0&&bounding.left>=0&&bounding.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&bounding.right<=(window.innerWidth||document.documentElement.clientWidth));};
    ${visible}=    execute_script    ${js} return isInViewport(${element});
    [Return]    ${visible}

Get Format Null Label
    [Arguments]    ${CssSelector}
    [Documentation]    获取数据错误和必填字段的label
    ${s2l}=    Get Library Instance    Selenium2Library
    ${js}=    Set Variable    function GetRequeryNotFilledLabel(classtype){var labels=document.getElementsByClassName(classtype);var length=labels.length;var texts=new Array();for(i=0;i<length;i++){var text=labels[i].parentNode.previousElementSibling.innerText;texts.push(text);}return texts;};
    #${texts}=    Call Method    ${s2l._current_browser()}    execute_script    ${js} return GetRequeryNotFilledLabel(${CssSelector});
    ${texts}=    Execute JavaScript    ${js} return GetRequeryNotFilledLabel(${CssSelector});
    [Return]    ${texts}

Set Style Display
    [Arguments]    ${id}    ${style}
    ${js}=    Set Variable    document.getElementById("${id}").style.display="${style}"
    Execute Javascript    ${js}

Element Click JS
    [Arguments]    ${css}
    ${js}=    Set Variable    document.querySelector('${css}').click()
    ${ret}=    Execute JavaScript    ${js}
